package com.gooluke.spring.web;

import com.gooluke.spring.annotation.ResponseBody;
import com.gooluke.spring.util.AnnotationUtils;

import java.lang.reflect.Method;

/**
 * @author gooluke
 * description
 * datetime 2025-04-14 23:48
 */
public class WebHandler {

    private Object controllerBean;
    private Method method;
    private ResultType resultType;

    public WebHandler(Object controllerBean, Method method) {
        this.controllerBean = controllerBean;
        this.method = method;
        this.resultType = resovleResultType(controllerBean, method);
    }

    private ResultType resovleResultType(Object controllerBean, Method method) {
        if (AnnotationUtils.hasAnnotation(controllerBean.getClass(), ResponseBody.class) || method.isAnnotationPresent(ResponseBody.class)) {
            return ResultType.JSON;
        } else {
            return ResultType.HTML;
        }
    }


    public Object getControllerBean() {
        return controllerBean;
    }

    public void setControllerBean(Object controllerBean) {
        this.controllerBean = controllerBean;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public ResultType getResultType() {
        return resultType;
    }

    public void setResultType(ResultType resultType) {
        this.resultType = resultType;
    }

    enum ResultType {
        JSON, HTML, LOCAL
    }
}
